package com.ruoyi.web.controller.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.web.controller.demo.domain.SysWzxUser;
import com.ruoyi.web.controller.mapper.SysMeetroomMapper;
import com.ruoyi.web.controller.demo.domain.SysMeetroom;
import com.ruoyi.web.controller.service.ISysMeetroomService;
import com.ruoyi.common.core.text.Convert;

/**
 * sys_meet_roomService业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-28
 */
@Service
public class SysMeetroomServiceImpl implements ISysMeetroomService 
{
    @Autowired
    private SysMeetroomMapper sysMeetroomMapper;

    /**
     * 查询sys_meet_room
     * 
     * @param id sys_meet_room主键
     * @return sys_meet_room
     */
    @Override
    public SysMeetroom selectSysMeetroomById(Long id)
    {
        return sysMeetroomMapper.selectSysMeetroomById(id);
    }

    /**
     * 查询sys_meet_room列表
     * 
     * @param sysMeetroom sys_meet_room
     * @return sys_meet_room
     */
    @Override
    public List<SysMeetroom> selectSysMeetroomList(SysMeetroom sysMeetroom)
    {
        return sysMeetroomMapper.selectSysMeetroomList(sysMeetroom);
    }

    /**
     * 新增sys_meet_room
     * 
     * @param sysMeetroom sys_meet_room
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysMeetroom(SysMeetroom sysMeetroom)
    {
        sysMeetroom.setCreateTime(DateUtils.getNowDate());
        int rows = sysMeetroomMapper.insertSysMeetroom(sysMeetroom);
        insertSysWzxUser(sysMeetroom);
        return rows;
    }

    /**
     * 修改sys_meet_room
     * 
     * @param sysMeetroom sys_meet_room
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysMeetroom(SysMeetroom sysMeetroom)
    {
//        sysMeetroomMapper.deleteSysWzxUserByUserId(sysMeetroom.getId());
        insertSysWzxUser(sysMeetroom);
        return sysMeetroomMapper.updateSysMeetroom(sysMeetroom);
    }

    /**
     * 批量删除sys_meet_room
     * 
     * @param ids 需要删除的sys_meet_room主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysMeetroomByIds(String ids)
    {
//        sysMeetroomMapper.deleteSysWzxUserByUserIds(Convert.toStrArray(ids));
        return sysMeetroomMapper.deleteSysMeetroomByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除sys_meet_room信息
     * 
     * @param id sys_meet_room主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysMeetroomById(Long id)
    {
//        sysMeetroomMapper.deleteSysWzxUserByUserId(id);
        return sysMeetroomMapper.deleteSysMeetroomById(id);
    }

    /**
     * 新增人员信息信息
     * 
     * @param sysMeetroom sys_meet_room对象
     */
    public void insertSysWzxUser(SysMeetroom sysMeetroom)
    {
        List<SysWzxUser> sysWzxUserList = sysMeetroom.getSysWzxUserList();
        Long id = sysMeetroom.getId();
        if (StringUtils.isNotNull(sysWzxUserList))
        {
            List<SysWzxUser> list = new ArrayList<SysWzxUser>();
            for (SysWzxUser sysWzxUser : sysWzxUserList)
            {
                sysWzxUser.setUserId(id);
                list.add(sysWzxUser);
            }
            if (list.size() > 0)
            {
                sysMeetroomMapper.batchSysWzxUser(list);
            }
        }
    }
}
